from sqlalchemy import Column, Integer, String, Text, BigInteger, CHAR, ForeignKey
from sqlalchemy.dialects.mysql import INTEGER, TINYINT, DECIMAL
from mooc.db.database import Base





# CoreAttachment模型用于映射数据库表ims_core_attachment
class CoreAttachment(Base):
    __tablename__ = "ims_core_attachment"

    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    uid = Column(INTEGER(unsigned=True), nullable=False)
    filename = Column(String(255), nullable=False)
    attachment = Column(String(255), nullable=False)
    type = Column(INTEGER(unsigned=True), nullable=False)
    createtime = Column(INTEGER(unsigned=True), nullable=False)
    module_upload_dir = Column(String(100), nullable=False)
    group_id = Column(Integer, nullable=False)
    displayorder = Column(Integer, nullable=False)

    class Config:
         from_attributes = True    

# CoreCache模型用于映射数据库表ims_core_cache
class CoreCache(Base):
    __tablename__ = "ims_core_cache"

    acid = Column(String(100), primary_key=True)  # 将key视为一种特殊的主键，这里用acid替代原本的命名方式
    value = Column(Text, nullable=False)
    class Config:
         from_attributes = True


# CoreCron模型用于映射数据库表ims_core_cron
class CoreCron(Base):
    __tablename__ = "ims_core_cron"
    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    cloudid = Column(INTEGER(unsigned=True), nullable=False)
    module = Column(String(50), nullable=False)
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    type = Column(TINYINT, nullable=False)
    name = Column(String(50), nullable=False)
    filename = Column(String(50), nullable=False)
    lastruntime = Column(INTEGER(unsigned=True), nullable=False)
    nextruntime = Column(INTEGER(unsigned=True), nullable=False)
    weekday = Column(TINYINT, nullable=False)
    day = Column(TINYINT, nullable=False)
    hour = Column(TINYINT, nullable=False)
    minute = Column(String(255), nullable=False)
    extra = Column(String(5000), nullable=False)
    status = Column(TINYINT, nullable=False)
    createtime = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True




# CoreCronRecord模型用于映射数据库表ims_core_cron_record
class CoreCronRecord(Base):
    __tablename__ = "ims_core_cron_record"
    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    module = Column(String(50), nullable=False)
    type = Column(String(50), nullable=False)
    tid = Column(INTEGER(unsigned=True), nullable=False)
    note = Column(String(500), nullable=False)
    tag = Column(String(5000), nullable=False)
    createtime = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True


# CoreJob模型用于映射数据库表ims_core_job
class CoreJob(Base):
    __tablename__ = "ims_core_job"
    acid = Column(Integer, primary_key=True)  # 将id改为acid
    type = Column(TINYINT, nullable=False)
    uniacid = Column(Integer, nullable=False)
    payload = Column(String(255), nullable=False)
    status = Column(TINYINT, nullable=False)
    title = Column(String(22), nullable=False)
    handled = Column(Integer, nullable=False)
    total = Column(Integer, nullable=False)
    createtime = Column(Integer, nullable=False)
    updatetime = Column(Integer, nullable=False)
    endtime = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False)
    isdeleted = Column(TINYINT, nullable=True)

    class Config:
         from_attributes = True



# CoreMenu模型用于映射数据库表ims_core_menu
class CoreMenu(Base):
    __tablename__ = "ims_core_menu"
    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    pid = Column(INTEGER(unsigned=True), nullable=False)
    title = Column(String(20), nullable=False)
    name = Column(String(20), nullable=False)
    url = Column(String(255), nullable=False)
    append_title = Column(String(30), nullable=False)
    append_url = Column(String(255), nullable=False)
    displayorder = Column(TINYINT, nullable=False)
    type = Column(String(15), nullable=False)
    is_display = Column(TINYINT, nullable=False)
    is_system = Column(TINYINT, nullable=False)
    permission_name = Column(String(50), nullable=False)
    group_name = Column(String(30), nullable=False)
    icon = Column(String(20), nullable=False)

    class Config:
         from_attributes = True


# CoreMenuShortcut模型用于映射数据库表ims_core_menu_shortcut
class CoreMenuShortcut(Base):
    __tablename__ = "ims_core_menu_shortcut"
    acid = Column(Integer, primary_key=True)  # 将id改为acid
    uid = Column(Integer, nullable=False)
    uniacid = Column(Integer, nullable=False)
    modulename = Column(String(100), nullable=False)
    displayorder = Column(Integer, nullable=False)
    position = Column(String(100), nullable=False)
    updatetime = Column(Integer, nullable=False)

    class Config:
         from_attributes = True



# CorePaylog模型用于映射数据库表ims_core_paylog
class CorePaylog(Base):
    __tablename__ = "ims_core_paylog"
    acid = Column(BigInteger, primary_key=True, nullable=False)  # 将plid改为acid，注意类型为BigInt
    type = Column(String(20), nullable=False)
    uniacid = Column(Integer, nullable=False)
    acid_original = Column(Integer, nullable=False)  # 原表中还有个acid字段，这里为避免混淆改名，可按需调整
    openid = Column(String(40), nullable=False)
    uniontid = Column(String(64), nullable=False)
    tid = Column(String(128), nullable=False)
    fee = Column(DECIMAL(10, 2), nullable=False)
    status = Column(TINYINT, nullable=False)
    module = Column(String(50), nullable=False)
    tag = Column(String(2000), nullable=False)
    is_usecard = Column(TINYINT, nullable=False)
    card_type = Column(TINYINT, nullable=False)
    card_id = Column(String(50), nullable=False)
    card_fee = Column(DECIMAL(10, 2), nullable=False)
    encrypt_code = Column(String(100), nullable=False)
    is_wish = Column(TINYINT, nullable=False)

    class Config:
         from_attributes = True


# CorePerformance模型用于映射数据库表ims_core_performance
class CorePerformance(Base):
    __tablename__ = "ims_core_performance"
    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    type = Column(TINYINT, nullable=False)
    runtime = Column(String(10), nullable=False)
    runurl = Column(String(512), nullable=False)
    runsql = Column(String(512), nullable=False)
    createtime = Column(Integer, nullable=False)

    class Config:
         from_attributes = True



# CoreQueue模型用于映射数据库表ims_core_queue
class CoreQueue(Base):
    __tablename__ = "ims_core_queue"
    acid = Column(BigInteger, primary_key=True)  # 将qid改为acid，类型对应BigInt
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    acid_original = Column(INTEGER(unsigned=True), nullable=False)  # 原表中还有acid字段，这里改名避免混淆，可按需调整
    message = Column(String(2000), nullable=False)
    params = Column(String(1000), nullable=False)
    keyword = Column(String(1000), nullable=False)
    response = Column(String(2000), nullable=False)
    module = Column(String(50), nullable=False)
    type = Column(TINYINT, nullable=False)
    dateline = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True


# CoreRefundlog模型用于映射数据库表ims_core_refundlog
class CoreRefundlog(Base):
    __tablename__ = "ims_core_refundlog"
    acid = Column(Integer, primary_key=True)  # 将id改为acid
    uniacid = Column(Integer, nullable=False)
    refund_uniontid = Column(String(64), nullable=False)
    reason = Column(String(80), nullable=False)
    uniontid = Column(String(64), nullable=False)
    fee = Column(DECIMAL(10, 2), nullable=False)
    status = Column(Integer, nullable=False)
    is_wish = Column(TINYINT, nullable=False)

    class Config:
         from_attributes = True


# CoreResource模型用于映射数据库表ims_core_resource
class CoreResource(Base):
    __tablename__ = "ims_core_resource"
    acid = Column(Integer, primary_key=True)  # 将mid改为acid
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    media_id = Column(String(100), nullable=False)
    trunk = Column(INTEGER(unsigned=True), nullable=False)
    type = Column(String(10), nullable=False)
    dateline = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True


# CoreSendsmsLog模型用于映射数据库表ims_core_sendsms_log
class CoreSendsmsLog(Base):
    __tablename__ = "ims_core_sendsms_log"
    acid = Column(INTEGER(unsigned=True), primary_key=True)  # 将id改为acid
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    mobile = Column(String(11), nullable=False)
    content = Column(String(255), nullable=False)
    result = Column(String(255), nullable=False)
    createtime = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True


# CoreSessions模型用于映射数据库表ims_core_sessions
class CoreSessions(Base):
    __tablename__ = "ims_core_sessions"
    acid = Column(CHAR(32), primary_key=True)  # 将sid作为主键，对应类型为CHAR(32)
    uniacid = Column(INTEGER(unsigned=True), nullable=False)
    openid = Column(String(50), nullable=False)
    data = Column(String(2000), nullable=False)
    expiretime = Column(INTEGER(unsigned=True), nullable=False)

    class Config:
         from_attributes = True

# CoreSettings模型用于映射数据库表ims_core_settings
class CoreSettings(Base):
    __tablename__ = "ims_core_settings"
    acid = Column(String(255), primary_key=True)  # 将主键key改为acid

    class Config:
         from_attributes = True